package yl.hs.bmipfull.service.finance.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yl.hs.bmipfull.daos.finance.IShipLedgerDao;
import yl.hs.bmipfull.pojo.salemanage.SaleContractEntity;
import yl.hs.bmipfull.service.finance.IShipLedgerService;
import yl.hs.bmipfull.utils.SearchFilterEngine;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.PageResult;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ShipLedgerServiceImpl extends FinanceService implements IShipLedgerService {
    @Override
    public PageResult<Map<String, Object>> queryShipLedger(PageQuery pageQuery, int rowNum, int page) {
        pageQuery.checkSortSides(SaleContractEntity.class);
        pageQuery.getQuery().put("querySkip", (page - 1) * rowNum);
        pageQuery.getQuery().put("pageSize", rowNum);
        PageResult<Map<String, Object>> result = new PageResult(rowNum);
        var filters = SearchFilterEngine.generateQueryList(pageQuery.getFilters(),SaleContractEntity.class);
        result.setRecords(ledgerDao.queryCountByCondition(pageQuery.getQuery(), filters));
        result.setPage(page);
        var scList = ledgerDao.queryPage(pageQuery.getQuery(), filters);
        List<Map<String,Object>> dataList = new ArrayList<>();
        result.setData(dataList);
        return result;
    }

    @Autowired
    IShipLedgerDao ledgerDao;
}
